package game.tileMap.model
{
	
	
	import com.adobe.utils.ArrayUtil;
	
	import game.tileMap.model.vo.ActorVo;
	import game.tileMap.model.vo.Skill;
	
	/**
	 * 
	 * @author maikid
	 * 己方角色
	 */	
	
	public class Actor extends Battler
	{
		private var vo:ActorVo
		public var  actor_id:String ;
		
		  public var character_name :String          // 角色行走图文件名
		  public var character_index  :int        // 角色行走图索引
		  public var face_name   :String             // 角色头像文件名
		  public var face_index  :int             // 角色头像索引
		  public var class_id    :String             // 职业 ID
		  public var weapon_id                // 武器 ID
		  public var armor1_id                // 盾 ID
		  public var armor2_id                // 头部防具 ID
		  public var armor3_id                // 身体防具 ID
		  public var armor4_id                // 装饰品 ID
		  public var level  :int=1;              // 等级
		  public var exp  :int                    // 经验值
		  
		  
		  public var learnPoint:int;
		//public var learning:Learning;
		  
		public var plural:Boolean;
	
		public function Actor(id:String)
		{
			super();
			this.index = index;
    		actor_id = id;
    		
    		this.vo= db.getActorVo(actor_id);
    		
    		plural = false
    		
    		battler_name = vo.battler_name
			name=battler_name;
    		battler_hue = vo.battler_hue
    		
    		
			setup(id);
			skillIdList=vo.skills;
			hp = maxhp
			mp = maxmp
			through=false;
			trace("人物名"+vo.name,"skill:"+skillIdList)
			//learning=new Learning();
		}
		
		override protected function init():void{
			super.init();
			
			
		}
		
		public function setup(actor_id:String):void{
//			actor = $data_actors[actor_id]
//		    this.actor_id = actor_id
//		    this.name = actor.name
//		    this.character_name = actor.character_name
//		    this.character_index = actor.character_index
//		    this.face_name = actor.face_name
//		    this.face_index = actor.face_index
//		    this.class_id = actor.class_id
//		    this.weapon_id = actor.weapon_id
//		    this.armor1_id = actor.armor1_id
//		    this.armor2_id = actor.armor2_id
//		    this.armor3_id = actor.armor3_id
//		    this.armor4_id = actor.armor4_id
		  //  this.level = actor.initial_level
		   // this.exp_list =new Array(101)
		   // make_exp_list
		   // this.exp = this.exp_list[this.level]
		  //  this.skills = []
//		    for i in self.class.learnings
//		       if (i.level <= this.level){
//		       	learn_skill(i.skill_id)
//		       }
//		    clear_extra_values
//		    recover_all
				
			
				//skillIdList=[3,1,2,4]
			
		}
   
		
		
		
	
		
//=======================================================================		
		override public function get base_maxhp():int{
			return vo.maxhp;
		}
		
		override public function get base_maxmp():int{
			return vo.maxmp;
		}
		
		override public function get base_atk():int{
			return vo.atk;
		}
		
		override public function get base_def():int{
			return vo.def;
		}
		
		override public function get base_spi():int{
			return vo.spi;
		}
		
		override public function get base_agi():int{
			return vo.agi;
		}
		
		override public function get hit():int{
			return vo.hit;
		}
		
		override public function get eva():int{
			return vo.eva;
		}
		
		//获取会心一击率
		override public function get cri():int{
			return 0
		}
		//获取受击率
		override public function get odds():int{
			return 1;
		}
		
//==============================================================================		
		
		
		public function isSkillLearn(skill:Skill):Boolean{
			
			/*if (skills.indexOf(skill.id)>-1){
				return true;
			}
				
			return false;*/
			
			return ArrayUtil.arrayContainsValue(skillIdList,skill.id);
		}
    	
    	override public function canUseSkill(skill:Skill):Boolean{
    		if (isSkillLearn(skill)){
    			return true
    		}
    		  
    		return super.canUseSkill(skill);
    	}
   
		
		public function learn_skill(skill_id:int):void{
//			var skill:Skill=db.getSkill(skill_id);
//			if (skill&&!isSkillLearn(skill)){
//			 	skillIdList.push(skill_id)
//		      	//skills.sort!
//			 }
		}
   
		public function gain_exp(exp:int):void
		{
			change_exp(exp)
			
		}
		
		private function change_exp(exp:int):void
		{
			leve_up();
			
		}
		
		private function leve_up():void
		{
			
			learnPoint+=level;
			level++;
		}
	}
}